<template>
	<view class="cart">
		<view class="cart-container">
			<!-- 收货地址 -->
			<my-address></my-address>
			<!-- 购物车展示列表 -->
			<view class="cart-show-list">
				<view class="cart-title">
					<uni-icons type="shop" size="22" color="black" />
					<text class="cart-text">购物车</text>
				</view>
				<!-- 列表项滑动删除 -->
				<uni-swipe-action>
					<uni-swipe-action-item v-for="item in cart" :key="item.goods_id" :right-options="options"
						@click="deleteGoodsItem(item.goods_id)">
						<my-lists :goodsItem="item" :showRadio="true" :showNumberBox="true"
							@radioStateEvent="radioStateHandler" @goodsNumberEvent="goodsNumberHandler"></my-lists>
					</uni-swipe-action-item>
				</uni-swipe-action>
			</view>
			<!-- 购物车结算区域 -->
			<my-settlement></my-settlement>
		</view>
	</view>
</template>

<script>
	import badgeMixin from '../../mixins/tabbarbage.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				// 滑动展示文本
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#c00000'
					}
				}]
			};
		},
		mixins: [badgeMixin],
		computed: {
			...mapState('m_cart', ['cart'])
		},
		methods: {
			...mapMutations('m_cart', ['changeGoodsState', 'changeGoodsNumber', 'removeGoods']),
			// 单选按钮事件处理函数
			radioStateHandler(id) {
				this.changeGoodsState(id);
			},
			// 商品数量改变事件处理函数
			goodsNumberHandler(goodsData) {
				this.changeGoodsNumber(goodsData);
			},
			// 从购物车中删除商品
			deleteGoodsItem(goodsId) {
				this.removeGoods(goodsId);
			}
		}
	}
</script>

<style lang="less">
	.cart {
		.cart-container {
			padding-bottom: 60px;

			.cart-show-list {
				.cart-title {
					width: 100%;
					padding: 10px 5px;
					font-size: 30rpx;
					display: flex;
					align-items: center;

					.cart-text {
						margin-left: 5px;
					}
				}
			}
		}
		.cart-empty{
			position: absolute;
			top: 40%;
			left: 50%;
			transform: translate(-50%,-50%);
			text-align: center;
			.empty-img{
				width: 100px;
				height: 100px;
			}
			.empty-text{
				font-size: 24rpx;
				color: gray;
			}
		}
	}
</style>
